package controller.human;

import java.util.HashMap;
import java.util.Map;

public class Person implements User, Player, Comparable<User>{
	Role role = Role.Citizen;
	PhysicalState physicalState = PhysicalState.Alive;
	int socialState = -1;
	String name;
	String password;
	
	private boolean display;
	//private boolean admin;
	
	static Map<String, Person> all = new HashMap<String, Person>();
	
	public Person(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	public PhysicalState getPhysicalState() {
		return physicalState;
	}
	public void setPhysicalState(PhysicalState physicalState) {
		this.physicalState = physicalState;
	}
	public int getSocialState() {
		return socialState;
	}
	public void setSocialState(int socialState) {
		this.socialState = socialState;
	}
	
	public static User getUser(String name) {
		Person p = all.get(name);
		if (p != null)
			return p;
		
		p = new Person(name);
		p.setDisplay(true);
		p.setPhysicalState(PhysicalState.Alive);
		p.setSocialState(-1);
		all.put(name, p);
		return p;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj==null) return false;
		return name.equals(((User)obj).getName());
	}
	
	@Override
	public int compareTo(User o) {
		if (o==null) return -1;
		return name.compareTo(o.getName());
	}
	public boolean isDisplay() {
		return display;
	}
	public void setDisplay(boolean display) {
		this.display = display;
	}
	@Override
	public boolean isProposed() {
		return socialState>=0;
	}
	public void incrementSocialState() {
		socialState++;
	}
	
	@Override
	public String toString() {
		return getName();
	}
//	public boolean isAdmin() {
//		return admin;
//	}
//	
//	public void setAdmin(boolean admin) {
//		this.admin = admin;
//	}
}
